package com.health.db.dao.user.impl;
 
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.health.db.dao.ServiceInterface;
import com.health.db.dao.user.ICourseShareRemarkDao;
import com.health.db.mapper.CourseShareRemarkMapper;
import com.health.db.model.CourseShareRemark;
import com.health.db.model.CourseShareRemarkExample;
import com.health.redis.RedisConstants;


@Component("courseShareRemarkDao")
public class CourseShareRemarkDaoImpl extends ServiceInterface implements ICourseShareRemarkDao {

	@Autowired
	private  CourseShareRemarkMapper courseShareRemarkMapper;
	String  userId=":userId:";
	
	String goodsId=":goodsId:";

	public CourseShareRemarkMapper getCourseShareRemarkMapper() {
		return courseShareRemarkMapper;
	}

	public void setCourseShareRemarkMapper(
			CourseShareRemarkMapper courseShareRemarkMapper) {
		this.courseShareRemarkMapper = courseShareRemarkMapper;
	}

	@Override
	public int insert(CourseShareRemark record) {
		// TODO Auto-generated method stub
		
		int result=courseShareRemarkMapper.insert(record);
		getRedisOperatiorLogic();
			
		String key = RedisConstants.CourseShareRemarkMapper+userId+record.getUserId().longValue();
		if(redisOperatiorLogic.isJedisIsConnected())
		{
			redisOperatiorLogic.deleteObject(key,getOrderRedisGroupNo("1"));

			if (null!=record.getGoodsId()) {
				key=key+goodsId+record.getGoodsId().longValue();
				redisOperatiorLogic.deleteObject(key,getOrderRedisGroupNo("1"));
				
			}
		}
		
		return result;
	}

	@Override
	public List<CourseShareRemark> selectByExample(
			CourseShareRemarkExample example) {
		// TODO Auto-generated method stub
		
		List<CourseShareRemark>  list =null;
		String key = RedisConstants.CourseShareRemarkMapper+userId+example.getUserId().longValue();
		
		if (null!=example.getGoodsId()) {
			key=key+goodsId+example.getGoodsId().longValue();
		}
		
		getRedisOperatiorLogic();
		Object object=null;
			
		if(redisOperatiorLogic.isJedisIsConnected())
		{
			object=redisOperatiorLogic.readObject(key, getOrderRedisGroupNo("1"));
		}
		if(null!=object )
		{
			if (!"".equals(object)) {
				list=(List<CourseShareRemark> ) object;
			}
		}
		else
		{
			list = courseShareRemarkMapper.selectByExample(example);
			
			if(redisOperatiorLogic.isJedisIsConnected())
			{
				redisOperatiorLogic.setEx(key, list, getOrderRedisGroupNo("1"));
			}
		}
		return list;
		
	}

	@Override
	public int updateByPrimaryKeySelective(CourseShareRemark record) {
		// TODO Auto-generated method stub
		
		int result=courseShareRemarkMapper.updateByPrimaryKeySelective(record);
		getRedisOperatiorLogic();
			
		String key = RedisConstants.CourseShareRemarkMapper+userId+record.getUserId().longValue();
		if(redisOperatiorLogic.isJedisIsConnected())
		{
			redisOperatiorLogic.deleteObject(key,getOrderRedisGroupNo("1"));

			if (null!=record.getGoodsId()) {
				key=key+goodsId+record.getGoodsId().longValue();
				redisOperatiorLogic.deleteObject(key,getOrderRedisGroupNo("1"));
				
			}
		}
		
		return result;
	}



	/**
	 * 无参数全表查询
	 *//*
	@Override
	public List<DoctorListDto> selectAllRecommond() {
		// TODO Auto-generated method stub
		
		getRedisOperatiorLogic();
     	String key=RedisConstants.StuffRecommondMapper;
     	Object object=null;
     	 List<DoctorListDto>  list=null; 
     
		 if(redisOperatiorLogic.isJedisIsConnected())
		 {
			 object=redisOperatiorLogic.readObject(key, getOrderRedisGroupNo("1"));
		 }
		 if(null!=object)
		 {
			 if ( !"".equals(object)) {
				 list=(List<DoctorListDto>) object;
			}
		 }
		 else
		 {
			 list = stuffRecommondMapper.selectAllRecommond();
			if(redisOperatiorLogic.isJedisIsConnected())
			 {
			 redisOperatiorLogic.setEx(key, list, getOrderRedisGroupNo("1"));
			 }
		 }
        return  list;
	}*/
}
